package main

import (
	"fmt"
	"math/rand"
	"time"
)

// 9*9乘法表
func multiplyTable1() {
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			if j == 1 {
				fmt.Printf("%d*%d=%-2d", j, i, j*i)
			} else {
				fmt.Printf("%d*%d=%-3d", j, i, j*i)
			}
		}
		fmt.Println()
	}
}

// 随机生成100以内的20个非0正整数，打印出来。对生成的数值，第单数个(不是索引)累加求和， 第偶数个累乘求积。打印结果:
func multiplyTable2() {
	r := rand.New(rand.NewSource(time.Now().UnixMicro()))
	limiter := 20
	var (
		sum            = 0
		product uint64 = 1
	)
	for i := 0; i < limiter; i++ {
		v := r.Intn(99) + 1
		fmt.Println("第", i+1, "非0正整数:", v)
		if i&1 == 0 {
			sum += v
		} else {
			product *= uint64(v)
		}
	}
	fmt.Println("累加求和:", sum, "累乘求积:", product)
}

// 打印100以内的斐波那契数列
func multiplyTable3() {
	a, b := 1, 1
	fmt.Println(a)
	fmt.Println(b)
	for {
		a, b = b, a+b
		if b > 100 {
			break
		}
		fmt.Println(b)
	}
}
func main() {
	fmt.Println("9*9乘法表:")
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~")
	multiplyTable1()
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Println("随机生成100以内的20个非0正整数,打印出来。对生成的数值,第单数个(不是索引)累加求和， 第偶数个累乘求积。打印结果:")
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~")
	multiplyTable2()
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Println("打印100以内的斐波那契数列:")
	multiplyTable3()
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~")
}
